# -*- coding:utf8 -*- #

# -----------------------------------------------------------------------------------

# Projectvalue:   property-ui-auto-test

# Filevalue:     read_ini

# Author:

# Datetime:    2022/5/2 16:08

# Description：

# -----------------------------------------------------------------------------------
import configparser
import os

"""
使用os模块，获取当前文件的目录，拼接文件的绝对路径
"""


class Config:
    def __init__(self):
        # 实例化对象
        self.config = configparser.ConfigParser()
        # 获取项目文件路径后通过common进行切分,选择第一段
        self.before_path = os.path.dirname(os.path.abspath(__file__)).split("common")[0]
        # 找到inin文件路径
        self.config.read(str(self.before_path) + r"data\config.ini", encoding="utf-8")

    # 声明方法，读取配置文件中的URL的path
    def get_url(self, option="smalleelTest") -> str:
        """
        :param option: 小鳗管家
        :return: 小鳗平台URL
        """

        return self.config.get("URL", option)

    # 声明方法，读取配置文件中的数据库信息
    def get_database_info(self, option) -> str:
        return self.config.get("Database", option)

    def get_json_path(self, option) -> str:
        file_path = self.config.get("Path", option)
        # 进行文件路径拼接
        return os.path.join(self.before_path, file_path)

    def get_excel_path(self) -> str:
        file_path = self.config.get("Path", "excel_path")
        # 进行文件路径拼接
        return os.path.join(self.before_path, file_path)

    def get_log_path(self) -> str:
        file_path = self.config.get("Path", "log_path")
        # 进行文件路径拼接
        return os.path.join(self.before_path, file_path)

    def get_screenshot_path(self) -> str:
        file_path = self.config.get("Path", "screenshot_path")
        # 进行文件路径拼接
        return os.path.join(self.before_path, file_path)

    def get_case_path(self) -> str:
        file_path = self.config.get("Path", "case_path")
        # 进行文件路径拼接
        return os.path.join(self.before_path, file_path)

    def get_report_path(self) -> str:
        file_path = self.config.get("Path", "report_path")
        # 进行文件路径拼接
        return os.path.join(self.before_path, file_path)

    def get_email_addr(self, value: str) -> list:
        if value.lower() == "all":
            valuePathlist = []
            emailPath = self.config.options("Email")
            for valuePath in emailPath:
                valuePathlist.append(self.config.get("Email", valuePath))
            return valuePathlist

        else:
            emailPath = [self.config.get("Email", value)]
            # 进行文件路径拼接
            return emailPath

    def get_email_config(self, value):
        return self.config.get("Email_config", value)

    def get_runner_config(self, option):
        config = self.config.get("RunnerConfig", option)
        # 进行文件路径拼接
        return config


if __name__ == '__main__':
    read_ini = Config()
    print(read_ini.get_url())
